{% extends "profiles/base.html" %}

{% load i18n %}
{% load avatar_tags %}
{% load uni_form %}
{% load microblogging_tags %}
{% load blog_tags %}
{% load tagging_tags %}
{% load photo_tags %}
{% load threadedcommentstags %}

{% block head_title %}{% blocktrans %}Profile for {{ other_user }}{% endblocktrans %}{% endblock %}

{% block body %}
    
    <div class="right_panel">
        {% include "profiles/profile_right_panel.html" %}
    </div>
    
    <div class="left_panel">
        <div class="vcard">
            <div id="profile_avatar">
                <div><img src="{% avatar_url other_user 80 %}" alt="Photo of {{ other_user }}" class="photo" /></div>
                {% if is_me %}
                <a href="{% url avatar_change %}" id="avatar_replace">(replace)</a>
                {% endif %}
            </div>
            
            {% if other_user.get_profile.name %}
                <h1>{% blocktrans %}Profile for <span class="nickname">{{ other_user }}</span>{% endblocktrans %}</h1>
            {% else %}
                <h1>{% blocktrans %}Profile for <span class="fn nickname">{{ other_user }}</span>{% endblocktrans %}</h1>
            {% endif %}
            
            <div class="profile_info">
                {% if other_user.get_profile.name %}<p><b>{% trans "Name" %}</b>: <span class="fn">{{ other_user.get_profile.name }}</span></p>{% endif %}
                {% if other_user.get_profile.about %}<p><b>{% trans "About" %}</b>: {{ other_user.get_profile.about }}</p>{% endif %}
                <!--{% if other_user.get_profile.location%}<p><b>{% trans "Location" %}</b>: {{ other_user.get_profile.location }}</p>{% endif %}-->
                {% if other_user.get_profile.website %}<p><b>{% trans "Website" %}</b>: <a class="url" href="{{ other_user.get_profile.website }}">{{ other_user.get_profile.website }}</a></p>{% endif %}
            </div>
            
            {% if is_me %}
                <p><a href="{% url profile_edit %}" rel="facebox">Edit profile</a></p>
            {% endif %}
            
            {% if user.is_authenticated %}
                <p>
                    <a href="{% url tweet_followers other_user %}">{% trans "Followers" %}</a>: {% follower_count other_user %}
                    <a href="{% url tweet_following other_user %}">{% trans "Following" %}</a>: {% following_count other_user %}
                </p>
                
                {% if is_me %}
                {% else %}
                    {# @@@ this could be done with ajax, or at the very least turned into an inclusion tag #}
                    <div>
                        <form method="POST" action="{% url toggle_follow other_user %}">
                            {% if is_following %}
                                <input type="hidden" name="action" value="unfollow" /><input type="submit" value="{% trans "unfollow" %}"/>
                            {% else %}
                                <input type="hidden" name="action" value="follow" /><input type="submit" value="{% trans "follow tweets" %}"/>
                            {% endif %}
                        </form>
                    </div>
                    
                    {# @@@ this should be an inclusion tag #}
                    {% if is_friend %}
                        <p>{% blocktrans %}You are friends with {{ other_user }}.{% endblocktrans %} <a href="{% url messages_compose %}{{ other_user }}/">{% trans "Send a message" %}</a>.</p>
                        <div>
                            <form method="POST" action="">
                                <input type="hidden" name="action" value="remove" /><input type="submit" value="{% trans "remove from friends" %}"/>
                            </form>
                        </div>
                    {% else %}
                        {% if previous_invitations_from %}
                            <p>{% blocktrans %}{{ other_user }} has requested friendship.{% endblocktrans %}</p>
                            {% for invitation in previous_invitations_from %}
                                <div class="friendship_request">
                                    <p>From <a href="{% url profile_detail invitation.from_user.username %}">{{ invitation.from_user }}</a> ({{ invitation.sent }}):</p>
                                    <p class="invitation_message">{{ invitation.message }}</p>
                                    <form method="post" action="">
                                        <input type="hidden" name="invitation" value="{{ invitation.id }}"/>
                                        <input type="hidden" name="action" value="accept"/>
                                        <input type="submit" value="{% trans 'accept' %}" />
                                    </form>
                                    <form method="post" action="">
                                        <input type="hidden" name="invitation" value="{{ invitation.id }}"/>
                                        <input type="hidden" name="action" value="decline"/>
                                        <input type="submit" value="{% trans 'decline' %}" />
                                    </form>
                                </div>
                            {% endfor %}
                        {% else %}
                            {% if previous_invitations_to %}
                                <p>{% trans "Friendship request sent." %}</p>
                            {% else %}
                                <h2>{% trans "Add As Friend" %}</h2>
                                <form class="uniForm" method="POST" action="">
                                    <fieldset class="inlineLabels">
                                        {{ invite_form|as_uni_form }}
                                        <div class="form_block">
                                            <input type="hidden" name="action" value="invite" />
                                            <input type="submit" value="{% trans "invite" %}"/>
                                            {% blocktrans %}{{ other_user }} to be a friend.{%  endblocktrans %}
                                        </div>
                                    </fieldset>
                                </form>
                            {% endif %} {# previous_invitations_to #}
                        {% endif %} {# previous_invitations_from #}
                    {% endif %} {# is_friend #}
                    
                {% endif %} {# is me #}
                
                <h2>{% trans "Blog Posts" %}</h2>
                
                {% if other_user.added_posts.all %}
                    {% for blog_post in other_user.added_posts.all %}
                        {% show_blog_post blog_post %}
                    {% endfor %}
                {% else %}
                    {% trans "No blog posts yet." %}
                {% endif %}
                
                
                <h2>{% trans "Tweets" %}</h2>
                
                {% if user.is_authenticated and is_me %}
                    {% sent_tweet_listing user 0 is_me %}
                {% else %}
                    {% sent_tweet_listing other_user 0 is_me %}
                {% endif %}
                
                
                <h2>{% trans "Photos" %}</h2>
                
                {% public_photos for other_user as photos %}
                
                {% if photos %}
                    <div class="clearfix">
                    {% for photo in photos %}
                        <div class="gallery-photo-thumb">
                            <a href="/photos/details/{{ photo.id }}/"><img src="{{ photo.get_thumbnail_url }}" alt="{{ photo.title }}"/></a>
                        </div>
                    {% endfor %}
                    </div>
                {% else %}
                   {% trans "No photos uploaded yet." %}
                {% endif %}
                
            {% else %} {# not user.is_authenticated #}
                {% url acct_signup as signup_url %}
                {% url acct_login as login_url %}
                <p>{% blocktrans %}<a href="{{ signup_url }}">Sign up</a> and <a href="{{ login_url }}">log in </a> to add this person as a friend and see their tweets and blog posts.{% endblocktrans %}</p>
            {% endif %}
        </div><!--/vcard-->
    </div>
{% endblock %}

{% block extra_body %}
    <script src="{{ STATIC_URL }}pinax/js/avatar.js" type="text/javascript"></script>
{% endblock %}
